﻿using System.Collections.Generic;
using System.Text;

namespace Beeflys.Generator
{
    sealed class Mapper
    {
        public static string Namespace = string.Empty;
        
        private static Dictionary<string, UTypeInfo> map = new Dictionary<string, UTypeInfo>();

        public static List<UTypeInfo> Types
        {
            get { return new List<UTypeInfo>(map.Values); }
        }

        public static void Add(UTypeInfo unit)
        {
            if (map.ContainsKey(unit.FullName))
            {
                return;
            }
            
            map.Add(unit.FullName, unit);
        }

        public static bool Contains(string fullName)
        {
            return map.ContainsKey(fullName);
        }

        public static UTypeInfo Get(string fullName)
        {
            if (Contains(fullName))
            {
                return map[fullName];
            }

            return null;
        }

        public static string ToText()
        {
            StringBuilder sb = new StringBuilder();
            foreach (var item in map)
            {
                var unitType = item.Value;
                
                sb.AppendLine($"当前类型:{unitType.FullName}");
                sb.AppendLine($"继承的类：{unitType.BaseType?.FullName}");
                
                foreach (var interface_ in unitType.GetBaseInterfaces())
                {
                    sb.AppendLine($"继承的接口:{interface_.FullName}");
                }

                foreach (var property in unitType.Propertys)
                {
                    sb.AppendLine($"属性：{property.Name}");
                }
                
                foreach (var method in unitType.Methods)
                {
                    sb.AppendLine($"方法：{method.Name}");
                }
            }

            return sb.ToString();
        }
    }
}